const isJSON = str => {
  if (typeof str == 'string') {
    try {
      const obj = JSON.parse(str)
      if (typeof obj == 'object' && obj) return true
      else return false
    } catch (e) {
      return false
    }
  }
}

/**
 * 存储
 */
export const setStore = (key, content) => {
  try {
    if (!key) return
    const tof = typeof content
    if (tof === 'string') {
      window.localStorage.setItem(key, content)
    } else if (tof === 'object' && content) {
      window.localStorage.setItem(key, JSON.stringify(content))
    }
  } catch (e) {
    return
  }
}
/**
 * 获取
 */
export const getStore = key => {
  try {
    if (!key) return
    let _val = window.localStorage.getItem(key)
    if (!_val) return
    if (isJSON(_val)) return JSON.parse(_val)
    else return
  } catch (e) {
    return
  }
}
/**
 * 获取字符串
 */
export const getStoreStr = key => {
  if (!key) return
  return window.localStorage.getItem(key)
}
/**
 * 删除
 */
export const removeStore = key => {
  if (!key) return
  window.localStorage.removeItem(key)
}
